const app = getApp();
import { cardVoucherDetail,venueList } from "../../../api/my"
import { getStorage } from "../../../utils/localStorage"
import { baseUrl } from "../../../api/request"
import { getMapDistance } from "../../../utils/address"
Page({
    data: {
        navData: {
            level: 2,
            title: "核销码"
        },
        user: getStorage('user'),
        imgUrl: baseUrl,
        latlng: {},
        navMargin: app.globalData.navHeight + app.globalData.navTop,
        infoData:{},
        venuList:[],
    },
    onLoad(options) {
        this.getInfo(options.id);
        this.setData({
            user: getStorage('user'),
            imgUrl: baseUrl,
            latlng: getStorage("latLng"),
        });
    },
    onReady() {

    },
    onShow() {

    },
    //获取页面初始化数据
    getInfo(id) {
        cardVoucherDetail({ userId: this.data.user.id, userCouponId: id }).then(res => {
            this.setData({
                infoData:res.data.data
            });
            this.getVenueList(res.data.data.venueId);
        });
    },
    //获取商家列表
    getVenueList(id){
        let that = this.data;
        venueList({venueId:id}).then(res=>{
            res.data.data.forEach(item=>{
                item.imageScale = item.imageScale.split(",");
                item.distance = getMapDistance(that.latlng.lat, that.latlng.lng, item.latitude, item.longitude);
            });
            this.setData({
                venuList:res.data.data
            });
        });
    },
    //商家列表点击事件
    listTap(e){
        let item = e.currentTarget.dataset.item;
        wx.navigateTo({
          url: '/pagesShouYe/pages/changsuoDetail/index?id='+item.id,
        });
        console.log(item,'item');
    },
    //到这去点击事件
    goHere(e){
        let item = e.currentTarget.dataset.item;
        wx.openLocation({
          latitude: Number(item.latitude),
          longitude: Number(item.longitude),
        });
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})